package com.info.zhiduoduo.repository.mapper.invoice;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.invoice.PurchaseInvoiceRecordListDto;
import com.info.zhiduoduo.repository.entity.invoice.PurchaseInvoiceRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface PurchaseInvoiceRecordMapper extends BaseMapper<PurchaseInvoiceRecord> {

    @Select(" SELECT pir.*, " +
            " c.compname as companyName , " +
            " sm.managername as entryName  " +
            " FROM zdd_purchase_invoice_record pir " +
            " LEFT JOIN zdd_company c ON c.compid = pir.company_id " +
            " LEFT JOIN zdd_system_manager sm ON sm.managerid = pir.entered_by " +
            " WHERE pir.is_delete = 0 " +
            " AND pir.state = #{state} " +
            " AND IF(#{invoiceType} = 0,1 = 1,pir.invoice_type = #{invoiceType})  " +
            " AND IF(ISNULL(#{purchaserName}) OR #{purchaserName}='', 1=1, pir.purchaser_name like CONCAT('%',#{purchaserName},'%') )  " +
            " AND IF(ISNULL(#{companyName}) OR #{companyName}='', 1=1, c.compname like CONCAT('%',#{companyName},'%') )  " +
            " ORDER BY pir.createtime DESC ")
    List<PurchaseInvoiceRecordListDto> purchaseInvoiceRecordList(@Param("state") int state,
                                                                 @Param("invoiceType") int invoiceType,
                                                                 @Param("purchaserName") String purchaserName,
                                                                 @Param("companyName") String companyName);

}
